#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
ll a,b;
const ll MOD=7;
ll Kuai(ll n) {
	if (n==1) return 1;
	if (n==2) return 1;
//	if (a==0 && b==0) return 0;
	n=n-2;
	ll res[2][2]={1,0,0,1};
	ll T[2][2]={a,b,1,0};
	ll tmp[2][2];
	while (n) {
		if (n&1) {
			for (ll i=0; i<2; ++i) {
				for (ll j=0; j<2; ++j) {
					tmp[i][j]=0;
					for (ll k=0; k<2; ++k) {
						tmp[i][j]=(tmp[i][j]+res[i][k]*T[k][j])%MOD;
					}
				}
			}
			swap(tmp, res);
		}
		for (ll i=0; i<2; ++i) {
			for (ll j=0; j<2; ++j) {
				tmp[i][j]=0;
				for (ll k=0; k<2; ++k) {
					tmp[i][j]=(tmp[i][j]+T[i][k]*T[k][j])%MOD;
				}
			}
		}
		swap(tmp, T);
		n=n>>1;
	}
//	for (ll i=0; i<2; ++i) {
//		for (ll j=0; j<2; ++j) cout<<res[i][j]<<" ";
//		cout<<endl;
//	}
	ll ans=(res[0][0]+res[0][1])%MOD;
	if (ans<0) ans+=MOD;
	return ans;
}
int main() {
	ll n;
	while (cin>>a>>b>>n) {
		cout<<Kuai(n)<<endl;
	}
	return 0;
}
